package com.example.srpingsecurityoauth2.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName MySuccessHandler
 * @Description
 * @Author gqz
 * @Date 2021/12/31 16:22
 * @Version 1.0
 **/
@Component
@Slf4j
public class MySuccessHandler implements AuthenticationSuccessHandler {

    @Value("${login.success-url}")
    private String successUrl;

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
         log.info("认证通过。。。");
         httpServletResponse.sendRedirect(successUrl);
    }
}
